<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2022-02-18 09:27:02
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-03-22 14:59:57
-->
<template>
  <div>
    <el-table
      v-loading="loading"
      :data="certInfoList"
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      height="490"
      row-key="id"
    >
      <template slot="empty" class="emptyBg">
        <img src="@/assets/images/empty.jpg" alt="" />
      </template>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="证书名称" fixed align="center" prop="certTypeId">
        <template slot-scope="scope">
          <span> {{ scope.row.certType.certName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="持有人" align="center" prop="belongerName" />
      <el-table-column
        label="身份证号"
        align="center"
        prop="idCard"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="证书主图" align="center" prop="remark">
        <template slot-scope="scope">
          <el-image
            style="width: 100%"
            :src="scope.row.remark"
            :preview-src-list="[scope.row.remark]"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column
        label="有效期"
        align="center"
        prop="certValidity"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.foreverValidity == "Y"
              ? "永久有效"
              : parseTime(scope.row.certValidity, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="certNumber">
        <template slot-scope="scope">
          {{
            scope.row.foreverValidity == "Y"
              ? "正常"
              : compareDate(scope.row.certValidity)
              ? "正常"
              : "已过期"
          }}
        </template>
      </el-table-column>
      <el-table-column label="借用状态" align="center" prop="certNumber">
        <template slot-scope="scope">
          {{ scope.row.loan == "Y" ? "借用" : "正常" }}
        </template>
      </el-table-column>
      <el-table-column label="借用人" align="center" prop="certNumber">
        <template slot-scope="scope">
          {{
            scope.row.loan == "Y" && scope.row.certUse
              ? scope.row.certUse.useUser
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="负责人" align="center" prop="directorName" />
      <el-table-column
        label="更新时间"
        align="center"
        prop="updateTime"
        width="180"
      />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listCertInfo } from "@/api/cert/certInfo";
export default {
  props: {
    drawerData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      lading: false,
      certInfoList: [],
      total: 0,
      tableData: [],
      certificate: [],
      // 查询参数
      queryParams: {
        searchValue: null,
        pageNum: 1,
        pageSize: 10,
        certTypeId: null,
        belonger: null,
        idCard: null,
        phone: null,
        certNumber: null,
        testPlace: null,
        issueDate: null,
        admissionTicket: null,
        issueUnit: null,
        certLocation: null,
        certValidity: null,
        foreverValidity: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 表格前多选器
    handleSelectionChange(val) {
      this.certificate = [];
      this.certificate = val;
    },
    /** 查询证书信息列表 */
    getList(val) {
      this.loading = true;
      listCertInfo({
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        sceneId: val,
        searchValue: this.queryParams.searchValue,
      }).then((response) => {
        this.certInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
        if (this.drawerData !== {}) {
          this.tableData.forEach((item) => {
            if (
              this.drawerData.certificate !== undefined &&
              this.drawerData.certificate !== null
            ) {
              //判断条件，根据自己的项目进行添加
              this.$refs.multipleTable.toggleRowSelection(item);
            }
          });
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>